package controllers

import (
	"context"
	beego "github.com/beego/beego/v2/server/web"
	"gorm.io/gorm"
	"strconv"
	"week/models"
)

type LookController struct {
	beego.Controller
}

func (l *LookController) Look() {
	anchor := l.GetString("anchor")
	userid := l.GetString("userid")
	aid, _ := strconv.Atoi(anchor)
	key := anchor + "blick:" + userid
	exists := models.Redis.Exists(context.Background(), key).Val()
	if exists != 0 {
		l.Data["json"] = map[string]interface{}{
			"code": 400,
			"msg":  "你已经被对方拉近黑名单",
		}
		l.ServeJSON()
		return
	}
	list, _ := models.GetAnchorInfo(models.BroudCast3{Model: gorm.Model{ID: uint(aid)}})
	if list.ID == 0 {
		l.Data["json"] = map[string]interface{}{
			"code": 400,
			"msg":  "主播不存在",
		}
		l.ServeJSON()
		return
	}
	l.Data["json"] = map[string]interface{}{
		"code": 200,
		"msg":  "进浏览器观看直播",
		"data": list.SowingMessage,
	}
	l.ServeJSON()
}
